package com.egao.common.module.recommendation.controller;

import com.egao.common.core.web.BaseController;
import com.egao.common.core.web.JsonResult;
import com.egao.common.core.web.PageParam;
import com.egao.common.core.web.PageResult;
import com.egao.common.module.recommendation.entity.DirectionalApplicationForm;
import com.egao.common.module.recommendation.entity.FreelanceRegistrationForm;
import com.egao.common.module.recommendation.entity.vo.RecommendationAuditParam;
import com.egao.common.module.recommendation.entity.vo.RecommendationListVo;
import com.egao.common.module.recommendation.service.IDirectionalApplicationFormService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 *  控制器
 *
 * @author cj
 */
@Api(tags = "管理")
@RestController
@RequestMapping("${api}")
public class DirectionalApplicationFormController extends BaseController {

    private IDirectionalApplicationFormService directionalApplicationFormService;

    @Autowired
    public DirectionalApplicationFormController(IDirectionalApplicationFormService directionalApplicationFormService){
        this.directionalApplicationFormService = directionalApplicationFormService;
    }

    @PreAuthorize("hasAuthority('dicForm:list')")
    @ApiOperation("查询列表")
    @GetMapping("/dirAppForm/list")
    public PageResult<RecommendationListVo> list(HttpServletRequest request) {
        PageParam<DirectionalApplicationForm> pageParam = new PageParam<>(request);
        return directionalApplicationFormService.list(pageParam);
    }

    @PreAuthorize("hasAuthority('dicForm:read')")
    @ApiOperation("查询单个")
    @GetMapping("/dirAppForm/get/{id}")
    public JsonResult read(@PathVariable("id") Integer id) {
        return directionalApplicationFormService.read(id);
    }

    @PreAuthorize("hasAuthority('dicForm:my')")
    @ApiOperation("查询单个")
    @GetMapping("/dirAppForm/my")
    public JsonResult read() {return directionalApplicationFormService.read();}

    @PreAuthorize("hasAuthority('dicForm:add')")
    @ApiOperation("添加")
    @PostMapping("/dirAppForm/add")
    public JsonResult add(@RequestBody DirectionalApplicationForm model) {
    return directionalApplicationFormService.add(model);
    }

//    暂存
    @PreAuthorize("hasAuthority('dicForm:update')")
    @ApiOperation("暂存")
    @PostMapping("/dirAppForm/update")
    public JsonResult update(@RequestBody DirectionalApplicationForm model) {
    return directionalApplicationFormService.update(model);
    }

    //   提交
    @PreAuthorize("hasAuthority('dicForm:submit')")
    @ApiOperation("提交")
    @PostMapping("/dirAppForm/submit/{id}")
    public JsonResult submit(@PathVariable("id") Integer id) {
        return directionalApplicationFormService.submit(id);
    }

    @PreAuthorize("hasAuthority('dicForm:delete')")
    @ApiOperation("删除")
    @GetMapping("/dirAppForm/delete/{ids}")
    public JsonResult delete(@PathVariable("ids") Integer[] ids) {
        return directionalApplicationFormService.delete(ids);
    }

    //    审核
    @PreAuthorize("hasAuthority('dicForm:audit')")
    @ApiOperation("审核")
    @PostMapping("/dirAppForm/audit")
    public JsonResult audit(@RequestBody RecommendationAuditParam param) {
        return directionalApplicationFormService.audit(param);
    }

    //  导出
    @PreAuthorize("hasAuthority('dicForm:export')")
    @ApiOperation("导出")
    @GetMapping("/dirAppForm/export/{id}")
    public JsonResult export(@PathVariable("id") Integer id, HttpServletResponse response) throws IOException {
        return directionalApplicationFormService.export(id,response);
    }

}